import { RouteRecordRaw } from "vue-router";
import APP_CONFIG from "@/core/config";

const tabbarRoutes: Array<RouteRecordRaw> = (() => {
  const { tabbar, openTabbar } = APP_CONFIG;
  const children = tabbar?.tabbarList.map(
    ({ title, path, name, component, keepAlive }) => ({
      path,
      name,
      component,
      meta: { title, keepAlive: !!keepAlive },
    })
  );
  const routes: any = openTabbar
    ? [
      {
        path: "/",
        name: "tabbar",
        redirect: children?.[0].path || "/",
        component: () => import("@/layouts/tabbar.vue"),
        children,
        meta: { keepAlive: true },
      },
    ]
    : [...(children || [])];
  return routes;
})();

const routes: Array<RouteRecordRaw> = [
  {
    path: "/",
    name: "home",
    component: () => import("@/views/home/index.vue"),
    meta: {
      title: "主页",
      keepAlive: false
    },
  },
  {
    path: "/work",
    name: "work",
    component: () => import("@/views/work/index.vue"),
    meta: {
      title: "工作",
    },
  },
];

export default routes;
